<?php


namespace app\model;


use app\util\Format;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
use think\model\concern\SoftDelete;

class SysUser extends Model
{
    use SoftDelete;

    protected $pk = "id";
    protected $readonly = ["id"];
    protected $autoWriteTimestamp = "datetime";

    protected $append = ["role_info"];


    /**
     * 获取角色信息
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getRoleInfoAttr()
    {
        return $this->hasOne(SysRole::class, "id", "role_id")->find();
    }
}